/*******************************************************************
 *     JameE
 *******************************************************************
  Copyright 2010 Clifford Champion and JameE contributors.
  
  This file is part of JameE.
  
  JameE is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  JameE is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with JameE.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************/
 
 
 
/// <reference path="~/Base/Classer.js" />
/// <reference path="~/Base/IncludeLoader.js" />

$include(
[
	"Engine/SceneObject.js"
]);

$class(
"JameE.Assets.Objects.Shape : SceneObject",
{
	/////////////////////
	// CONSTANTS
	/////////////
	SHAPE_SQUARE: 1,
	SHAPE_CIRCLE: 2,


	/////////////////////
	// FIELDS
	/////////////
	_iType: null,
	_strFillColor: null,
	_strOutlineColor: null,


	/////////////////////
	// CONSTRUCTORS
	/////////////
	_ctor: function () {
		this._iType = $argument("type", "number") || this.SHAPE_CIRCLE;

		var strDefaultColor = $argument("color", "string") || "#ff0000";
		this._strFillColor = $argument("fillcolor", "string") || strDefaultColor;
		this._strOutlineColor = $argument("outlinecolor", "string") || strDefaultColor;
	},


	/////////////////////
	// METHODS: ISceneObject
	/////////////
	draw: function (oContext) {

		// begin
		oContext.save();
		oContext.beginPath();

		// color
		oContext.fillStyle = this._strFillColor;
		oContext.strokeStyle = this._strOutlineColor;

		oContext.translate(this._oPosition.fX, this._oPosition.fY);

		// shape
		if (this._iType == this.SHAPE_CIRCLE) {
			oContext.scale(this._oDimensions.fX / 2, this._oDimensions.fY / 2);
			oContext.arc(0, 0, 1, 0, 2 * Math.PI, true);
			oContext.closePath();
		}
		else if (this._iType == this.SHAPE_SQUARE) {
			oContext.scale(this._oDimensions.fX / 2, this._oDimensions.fY / 2);
			oContext.rect(-1, -1, 2, 2);
			oContext.closePath();
		}

		// line size
		oContext.lineWidth = 1 / this._oDimensions.fX;

		// draw
		oContext.fill();
		oContext.stroke();

		// cleanup
		oContext.restore();

	}
});

$include_notify("Assets/Objects/Shape.js");

